//package com.tj.api.task;
//
//import com.fqgj.common.utils.CollectionUtils;
//import com.tj.bo.common.conf.config.RedisConfigUtil;
//import com.tj.bo.common.conf.util.IpUtils;
//import com.tj.bo.trade.client.enums.OrderStatusEnum;
//import com.tj.bo.trade.server.dao.BinaryTradeDao;
//import com.tj.bo.trade.server.entity.BinaryTradeEntity;
//import com.tj.bo.trade.server.service.TradeHandler;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Scheduled;
//
//import java.util.List;
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//
///**
// * @program: binary-option
// * @description 交易结算任务
// * @author: binary
// * @create: 2020-06-05 15:46
// **/
////@Component
//public class TradeSettlementTask {
//
//    private static final Logger LOGGER = LoggerFactory.getLogger(TradeSettlementTask.class);
//
//    @Autowired
//    private BinaryTradeDao binaryTradeDao;
//    @Autowired
//    private TradeHandler tradeHandler;
//    @Autowired
//    private RedisConfigUtil redisDbConfigUtil;
//
//    /**
//     * 结算开盘中的交易
//     */
//    @Scheduled(cron = "0 0/1 * * * ?")
//    public void settlementOrders() {
//
//        String ip = IpUtils.getIp();
//        String taskIp = redisDbConfigUtil.getTaskIp();
//        if (!taskIp.equalsIgnoreCase(ip)) {
//            LOGGER.info("============ IP不匹配不执行任务 taskIp:{}, localIp:{}  ==========", taskIp, ip);
//            return;
//        }
//        List<BinaryTradeEntity> binaryTradeEntities = binaryTradeDao.selectsBinaryTradeListByCondition(OrderStatusEnum.OPENING.getCode());
//        if (CollectionUtils.isEmpty(binaryTradeEntities)) {
//            LOGGER.info("============ 开盘中的交易列表为空 ==========");
//        }
//        ExecutorService executorService = Executors.newFixedThreadPool(20);
//        for (BinaryTradeEntity binaryTradeEntity : binaryTradeEntities) {
//            executorService.execute(() -> {
//                try {
//                    //tradeHandler.settlementOrders(binaryTradeEntity.getTradeNo());
//                } catch (Exception e) {
//                    LOGGER.error("========== 结算任务失败，tradeNo:{}, e =========", binaryTradeEntity.getTradeNo(), e);
//                }
//            });
//        }
//        LOGGER.info("============ 收盘任务Success ==========");
//    }
//
//}
